<template>
	<view class="" id="Mine">
		<view class="mine">
			<view class="header_top" :style="{height:version ? '444upx' : '300upx'}">
				<!-- #ifdef MP-WEIXIN -->
				<hx-navbar left-text="我的" :back="false" :fixed="true" :transparent="hidden" color="#ffffff"
					statusBarFontColor="#ffffff">
				</hx-navbar>
				<!-- #endif -->
				<view class="header_top_body" :style="{marginTop:version ? '30upx' : '50upx'}">
					<view class="top_pic" v-if="loginflag">
				 
						<image :src="uesData.user.avatar ? uesData.user.avatar:'/static/image/mine/avatar.png'"></image>
						<view class="top_info"> 
						 <view class="">
						 	{{uesData.user.nick_name ? uesData.user.nick_name:'新用户'}}
						 </view>
						 <view class="" style="margin-top: 20rpx;">
						 	{{uesData.user.mobile }}
						 </view>
						 </view>
					</view>
					<view class="top_pic" v-else @tap="login()">
						<image :src="Url+'add_images/no_login_header.png'" class="img_nologin"></image>
						<view class="top_info">去登录</view>
					</view>
					<view class="signin" @tap="tosignin()">
						<image :src="Url+'add_images/day_signin.png'"></image>签到
					</view>
				</view>

			</view>
			<!-- 积分优惠券 -->
			<!-- #ifdef MP-WEIXIN -->
			<view class="treasue">
				<view class="treasueItem" @tap="lookBalance">
					<view class="treasue_num">{{uesData.user.balance}}</view>
					<view class="treasue_title">账户余额</view>
				</view>
				<view class="treasueItem" @tap="lookintegral">
					<view class="treasue_num">{{uesData.user.integral}}</view>
					<view class="treasue_title">我的积分</view>
				</view>
				<view class="treasueItem" @tap="todiscount">
					<view class="treasue_num" v-if="loginflag">{{uesData.user.coupon}}<text>张</text></view>
					<view class="treasue_title">优惠券</view>
				</view>
			</view>
			<!-- #endif -->

			<!-- 订单信息 -->
			<view class="order">
				<view class="order_title">
					<view class=""> 我的订单</view>
					<view class="order_title_more" @tap="toorder">全部订单<i class="icon">&#xe637;</i></view>
				</view>
				<view class="order_class">
					<view class="order_class_info" v-for="(item, index) in orderList" :key="index"
						@tap="lookorder(index)">

						<image class="order_pic" :src="item.src" mode="widthFix"></image>
						<view class="order_all_content_info">{{ item.title }}</view>
						<view class="tag" v-if="item.showflag"></view>
					</view>
				</view>
			</view>
			<!-- 我的服务 -->
			<view class="service_x">
				<view class="service_title">我的服务</view>
				<view class="service_content">
					<!-- #ifdef MP-WEIXIN -->
					<view class="service_content_info" v-for="(item, key) in serviceList" @tap="toservice(key)"
						v-if="(key == 0 && uesData.assemble) || (key == 1 && uesData.integral) || (key != 0 && key != 1)">

						<view class="info_left">
							<image :src="item.src" mode="widthFix"></image>
							<view>{{ item.title }}</view>
						</view>
					</view>
					<!-- #endif -->
					<!-- #ifdef H5 -->
					<view class="service_content_info" v-for="(item, key) in serviceList" @tap="toservice(key)"
						v-if="item.title != '我的拼团' &&  item.title != '积分商城'" >

						<view class="info_left">
							<image :src="item.src" mode="widthFix"></image>
							<view>{{ item.title }}</view>
						</view>
					</view>
					<!-- #endif -->
				</view>
			</view>
		</view>
		<!-- 联系客服弹窗 -->
		<uni-customer ref='customer'></uni-customer>
		<shop-loading v-if="shopLoad"></shop-loading>
		<!-- <sign v-if="signflag" @changeflag="changeflag"></sign> -->
		<!-- <button @tap="login()">登录</button> -->
		<uni-login ref='login' @success="getUserData"></uni-login>
	</view>
</template>

<script>
	import sign from '@/components/sign/sign.vue';
	import uniCustomer from '@/components/customerService/customer_service.vue'
	import hxNavbar from '@/components/status-nav/hx-navbar.vue';
	import {
		getUser,
		about
	} from '@/common/mine.js';
	export default {
		components: {
			sign,
			uniCustomer,
			hxNavbar
		},
		data() {
			return {
				Url: this.Imgurl,
				signflag: false,
				loginflag: false,
				shopLoad: false,
				uesData: {},
				orderList: [{
						src: this.Imgurl + 'add_images/dindan_01.png',
						title: '待支付',
						showflag: false
					},
					{
						src: this.Imgurl + 'add_images/dindan_02.png',
						title: '待发货',
						showflag: false
					},
					{
						src: this.Imgurl + 'add_images/dindan_03.png',
						title: '待收货',
						showflag: false
					},
					{
						src: this.Imgurl + 'add_images/dindan_04.png',
						title: '已完成',
						showflag: false
					}
				],
				serviceList: [{
						src: this.Imgurl + 'add_images/groups.png',
						title: '我的拼团'
					},
					{
						src: this.Imgurl + 'add_images/integral_shop.png',
						title: '积分商城'
					},
					{
						src: this.Imgurl + 'add_images/mine_adress.png',
						title: '收货地址'
					},
					{
						src: this.Imgurl + 'add_images/about_our.png',
						title: '关于我们'
					},
					{
						src: this.Imgurl + 'add_images/cus_ser.png',
						title: '联系客服'
					}
				],
				version: uni.getSystemInfoSync().version
			};
		},
		onLoad() {
			this.shopLoad = true;
			this.getUserData()
			console.log('实例', this.StatusBar, this.CustomBar)
		},
		onShow() {
			this.$store.commit('CART_NUM');
			this.getUserData()
		},
		methods: {
			//获取页面数据
			getUserData() {
				getUser().then(res => {
					console.log(res)
					console.log(res.msg.state)
					if (res.code == 1) {
						this.loginflag = res.msg.user.id ? true : false
						console.log("是否登录状态", this.loginflag)
						this.uesData = res.msg
						if (this.uesData.not_pay) {
							this.orderList[0].showflag = true
						}
						if (this.uesData.not_deliver) {
							this.orderList[1].showflag = true
						}
						if (this.uesData.deliver) {
							this.orderList[2].showflag = true
						}
						this.shopLoad = false;
					} else {
						this.shopLoad = false;
					}
				}).catch()
			},
			//登录
			login() {
				uni.navigateTo({
					url:'/pages/login/login'
				})
				// if (uni.getSystemInfoSync().version) {
				// 	this.$refs.login.show = true;
				// }
			},
			//去签到页面
			tosignin() {
				if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
					this.login()
				} else {
					uni.navigateTo({
						url: '/pageA/signin/signin'
					})
				}
			},
			//去订单页面
			lookorder(key) {
				if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
					this.login()
				} else {
					uni.navigateTo({
						url: '/pageD/order/order?id=' + (key + 1)
					})
				}
			},
			//去账户余额页面
			lookBalance() {
				if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
					this.login()
				} else {
					if (this.uesData.recharge == 1) {
						uni.navigateTo({
							url: '/pageA/balance/balance'
						})
					}

				}
			},
			//去积分明细页面
			lookintegral() {
				if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
					this.login()
				} else {
					uni.navigateTo({
						url: '/pageA/integral/integral_detail'
					})
				}
			},
			//去全部订单页面
			toorder() {
				if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
					this.login()
				} else {
					uni.navigateTo({
						url: '/pageD/order/order?id=' + 0
					});
				}
			},
			changeflag() {
				this.signflag = false;
			},
			//我的服务点击事件
			toservice(key) {
				switch (key) {
					case 0:
						//我的拼团
						if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
							this.login()
						} else {
							uni.navigateTo({
								url: '/pageD/order/group_order'
							});
						}
						break;
					case 1:
						//积分商城
						uni.navigateTo({
							url: '/pageA/integral/integral'
						});
						break;
					case 2:
						// 收货地址
						if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
							this.login()
						} else {
							uni.navigateTo({
								url: '/pageD/adress/adress'
							});
						}
						break;
					case 3:
						//关于我们
						uni.navigateTo({
							url: '/pageD/about/about'
						});
						break;
					case 4:
						// 联系客服
						this.$refs.customer.show = true;
					default:
						break;
				}
			},
			//去优惠券页面
			todiscount() {
				if (!uni.getStorageSync('token') && uni.getSystemInfoSync().version) {
					this.login()
				} else {
					uni.navigateTo({
						url: '/pageD/discount/discount'
					});
				}
			},
			closestand() {
				this.$refs.customer.close();
			},
		}
	};
</script>

<style>
	page {
		background-color: #f8f8f8;
		overflow: hidden;
	}
</style>
<style lang="less" scoped>
	@import url('../../static/scss/mine/mine.less');
</style>